var app = getApp();
Component({
    properties: {
        isauth : Boolean,
        dolper : String,
        item : {
            type : Object,
            observer : function(newobj,old){
                if(newobj && old && this.data.isauth ){
                    this.data.ising = true;
                    this.setData({
                        item : newobj
                    },function(){
                        this.open();
                    })
                }
            }
        },
    },
    data: {
        popVisible: !1,
        date: {
            day: "00",
            hour: "00",
            minute: "00",
            second: "00"
        },
        timer: null,
        time: 0
    },
    ready:function(){
        if( this.data.isauth && !this.data.ising ) {
            this.data.ising = true;
            this.open();
        }
    },
    methods: {
        timeEnd: function() {
            clearInterval(this.data.timer);
            this.data.timer = null;
        },
        getCurrentTime: function(timedesc) {
            var self = this;
            self.timeEnd();

            if( !timedesc || timedesc <= 0 ) return false;

            var time = setInterval(function() {
                var i = new Date().getTime();
                var endTime = timedesc + '000';
                var lag = (endTime*1 - i);
                var second = minite = hour = day = 0;
                if(lag > 0){
                    var second = Math.floor(lag/1000%60);     
                    var minite = Math.floor(lag/1000/60%60);
                    var hour = Math.floor(lag/1000/60/60%24);
                    var day = Math.floor(lag/1000/60/60/24);
                }
                self.setData({
                    "date.day": day,
                    "date.hour": hour,
                    "date.minute": minite,
                    "date.second": second
                });
            },1000);

            this.setData({
                timer: time
            });

        },
        open: function() {
            var self = this;
            self.timeEnd();

            for (var i = 0; i < self.data.item.length; i++) {
                var item = self.data.item[i];
                if( item.isshow == 1 ){
                    self.setData({
                        ['item['+i+'].showed'] : 1,
                        ['item['+i+'].isshow'] : 0,
                    })
                }else{
                    if( !item.showed ){
                        self.setData({
                            ['item['+i+'].isshow'] : 1,
                        })

                        self.getCurrentTime(item.time);
                        return false;
                    }
                }
            }
        },
        location : function( e ){
            this.open();
            app.com.location( e );
        },
        other : function( e ){
            this.open();
            app.com.otherapp( e );
        },
        weburl : function(e){
            this.open();
            app.com.toweburl( e,this );
        },
        url : function( e ){
            this.open();
            app.com.navigateto( e );
        },   
        tel : function(e){
            this.open();
            app.com.callphone( e );
        },


    }
});